
	
	function sendObj(obj,uri){
		var login = $(obj).val();
		$.ajax({
			url : uri,
			type: 'POST',
			cache: false,
			data: {login : $(obj).val()},
			success: function(d){
				if(d == 0){
					$(obj).attr("data-content", "Login já cadastrado, por favor informe outro login");
	                $(obj).attr("data-placement", "bottom");
	                $(obj).attr("data-container", "body");
	                $(obj).popover({
	                    trigger: 'manual',
	                    html: false
	                });
	                $(obj).parent('div').addClass("has-error");
	                $(obj).popover("show");
	                $(obj).focus();
					
				}else{
					$(obj).popover("hide");
                    $(obj).parent('div').removeClass("has-error");
				}
			}
		});
	}
	
	function checarUser(obj){
		sendObj(obj, './ajax/checarlogin.php');
	}
	
	function checarUserAdm(obj){
		sendObj(obj, '../ajax/checarlogin.php')
	}
	
	function confereSenha(id1,id2){
		if($('#'+id2).val() != ""){
			if($('#'+id1).val() != $('#'+id2).val()){
				$('#'+id1).attr("data-content", "senha não confere, informe a mesma senha");
            	$('#'+id1).attr("data-placement", "bottom");
            	$('#'+id1).attr("data-container", "body");
            	$('#'+id1).popover({
                	trigger: 'manual',
                	html: false
            	});
            	$('#'+id1+', #'+id2).parent('div').addClass("has-error");
            	$('#'+id1).popover("show");
            	$('#'+id1).focus();
            	$('#'+id2).val("");
			}else{
				$('#'+id1).popover("hide");
            	$('#'+id1+', #'+id2).parent('div').removeClass("has-error");
			}
		}
	}
	function mudarEstado(obj,estado){
		if(estado == 'A'){
			var estado = 'A';
			var botao = '<button codigo="'+$(obj).attr('codigo')+'" class="btn btn-danger btn-xs" title="Desativar" onclick="mudarEstado(this,\'D\')"><span class="glyphicon glyphicon-remove-sign"></span></button>';
		}else{
			var estado = "P";
			var botao = '<button codigo="'+$(obj).attr('codigo')+'" class="btn btn-success btn-xs" title="Ativar" onclick="mudarEstado(this,\'A\')"><span class="glyphicon glyphicon-ok-sign"></span></button>'
		}
		$.ajax({
			url : "../ajax/ativaDesativa.php",
			type: 'POST',
			cache: false,
			data: {login : $(obj).attr('codigo'), situacao : estado},
			success: function(d){
				if(d == 0){
					$(obj).attr("data-content", "Usuário não foi habilitado/desabilitado, contate o administrador");
					$(obj).attr("data-placement", "bottom");
					$(obj).attr("data-container", "body");
					$(obj).popover({
						trigger: 'manual',
						html: false
					});
					$(obj).popover("show");
				}else{
					$(obj).popover("hide");
					$(obj).parent('td').prepend(botao);
					$(obj).remove();
				}
			}
		});
	}
